package com.ywjh.inter.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.ywjh.inter.entity.DocMedicineEntity;

public class DocMedicineDAO {

	public List<DocMedicineEntity> list(Connection conn) throws SQLException {
		List<DocMedicineEntity> list = new LinkedList<DocMedicineEntity>();
		PreparedStatement ps = conn.prepareStatement("select * from doc_medicine where status=1");
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DocMedicineEntity e = new DocMedicineEntity();
			e.setAdd_admin_id(rs.getInt("add_admin_id"));
			e.setAdd_time(rs.getTimestamp("add_time"));
			e.setId(rs.getInt("id"));
			e.setName(rs.getString("name"));
			e.setStatus(rs.getInt("status"));
			e.setDrugusage(rs.getString("drugusage"));
			e.setType_id(rs.getInt("type_id"));
			e.setUnit(rs.getString("unit"));
			list.add(e);
		}
		return list;
	}

	public List<DocMedicineEntity> listByType(Connection conn, int type) throws SQLException {
		List<DocMedicineEntity> list = new LinkedList<DocMedicineEntity>();
		PreparedStatement ps = conn.prepareStatement("select * from doc_medicine where status=1 and type_id=?");
		ps.setInt(1, type);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DocMedicineEntity e = new DocMedicineEntity();
			e.setAdd_admin_id(rs.getInt("add_admin_id"));
			e.setAdd_time(rs.getTimestamp("add_time"));
			e.setId(rs.getInt("id"));
			e.setName(rs.getString("name"));
			e.setStatus(rs.getInt("status"));
			e.setDrugusage(rs.getString("drugusage"));
			e.setType_id(rs.getInt("type_id"));
			e.setUnit(rs.getString("unit"));
			list.add(e);
		}
		return list;
	}
}
